package com.cn.service;

import com.cn.mapper.AccountMapper;
import com.cn.mapper.LogMapper;
import com.cn.pojo.Account;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class AccountServiceImpl implements AccountService {
    @Autowired
    private AccountMapper accountMapper;
    @Autowired
    private LogService logService;

    //@Override
    //public void transfer(String out, String in, Double money) {
    //    accountMapper.outMoney(out,money);
    //    //如果不使用事务管理，抛出错误后，转账减钱的操作已经发生，而加钱的操作不能进行，会导致转账错误，需要事务控制
    //    int i = 1/0;
    //    accountMapper.inMoney(in,money);
    //}

    public void transfer(String out,String in,Double money){
        try{
            accountMapper.outMoney(out,money);
            int i = 1/0;
            accountMapper.inMoney(in,money);
        }finally {
            logService.log(out,in,money);
        }
    }

}
